package com.sanpu.kxe.business.main.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.CreditEventOutput;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;
import com.sanpu.kxe.utils.ScreenUtil;

import java.util.ArrayList;

/**
 * Description：信用卡活动
 * Created by 薛勇军 on 2019/4/1.
 */

public class CreditEventAdapter extends BaseQuickAdapter<CreditEventOutput, BaseViewHolder> {

    private float imageHeight;

    public CreditEventAdapter(Context context) {
        super(R.layout.item_credit_event, new ArrayList<CreditEventOutput>());
        DisplayMetrics metric = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metric);
        int pxWidth = metric.widthPixels - ScreenUtil.dp2px(20);
        imageHeight = pxWidth * 305 / 601;
    }

    @Override
    protected void convert(BaseViewHolder helper, CreditEventOutput item) {
        ImageView creditEventIv = helper.getView(R.id.ivCreditEvent);
        View bottomLine = helper.getView(R.id.bottomLine);
        if (item != null) {
            if (!TextUtils.isEmpty(item.getAdPic())) {
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) creditEventIv.getLayoutParams();
                lp.height = (int) imageHeight;
                creditEventIv.setLayoutParams(lp);
                JKImageLoader.getInstance().displayImage(mContext, UrlConstants.getBaseUrl() + item.getAdPic(), creditEventIv);
            }
        }
        bottomLine.setVisibility(View.GONE);
        if (helper.getLayoutPosition() == getData().size() - 1) {
            bottomLine.setVisibility(View.VISIBLE);
        }
    }
}
